<template>
  <view class="list">
    <view :class="`list-item ${item.value === selectVal && 'list-item_select'}` " v-for="item in list" :key="item.value" @click="handleClick(item.value)">
      <image class="img" width="80px" mode="widthFix" :src="item.previewUrl"></image>
    </view>
  </view>
</template>

<script>
  export default {
    name: 'selectWordType',
    props: {
      value: {
        type: Number,
        default: ''
      }
    },
    data() {
      return {
        list: [{
            value: 1,
            previewUrl: 'https://mp-f94b3c95-ea57-45eb-aad5-8365caef5925.cdn.bspapp.com/avatar-client/homophonic-word-preview/top1.png'
          },
          {
              value: 2,
              previewUrl: 'https://mp-f94b3c95-ea57-45eb-aad5-8365caef5925.cdn.bspapp.com/avatar-client/homophonic-word-preview/top2.png'
            }
        ]
      }
    },
    computed: {
      selectVal: {
        get(val) {
          return this.value
        },
        set(val) {
          this.$emit('input', val)
        }
      }
    },
    mounted() {
    },
    methods: {
      handleClick(val) {
        this.selectVal = val
      }
    }
  }
</script>

<style lang="scss" scoped>
  .list {
    display: flex;
    flex-wrap: wrap;
    .list-item {
      margin-right: 10px;
      margin-top: 10px;
      .img {
        width: 80px;
      }
      &.list-item_select {
        border: 1px solid red;
      }
    }
  }
</style>